﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using Delay;

namespace PhoneInfo.Page
{
    public partial class SoftSiting : PhoneApplicationPage
    {
        public bool themloaded = false;
        public bool fontSizeloaded = false;
        public SoftSiting()
        {
            InitializeComponent();
            Pictrue.IsChecked = App.appSitting.IsNonPictrueMode;
            AutoLoadNextPage.IsChecked=App.appSitting.AutoLoadNextPage;
            ReturnRrompt.IsChecked=App.appSitting.IsReturnRrompt;
            ReturnClear.IsChecked = App.appSitting.IsReturnClear;
        }

      
        private void them_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (themloaded==false) return;
            ListPicker lp = sender as ListPicker;
            if (lp==null) return;
            App.appSitting.Theme = lp.SelectedIndex;
            App.ManagerDB.SubmitChanges();
            switch (lp.SelectedIndex)
            {
                case 0:
                    Theme.TurnDefaulet();
                    break;
                case 1:
                    Theme.TurnGreen();
                    break;
            }
        }
        private void fontSize_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if( fontSizeloaded == false) return;
            if (sender == null) return;
            ListPicker lp = sender as ListPicker;
            if (lp == null) return;
            App.appSitting.FontType = lp.SelectedIndex;
            App.ManagerDB.SubmitChanges();
            //调用相应的字体设置函数
        }   
        
       

        private void Pictrue_Checked(object sender, RoutedEventArgs e)
        {
            App.appSitting.IsNonPictrueMode = true;
            LowProfileXmlLoader.isNonPictureMode = App.appSitting.IsNonPictrueMode;
            App.ManagerDB.SubmitChanges();
        }

        private void Pictrue_Unchecked(object sender, RoutedEventArgs e)
        {
            App.appSitting.IsNonPictrueMode = false;
            LowProfileXmlLoader.isNonPictureMode = App.appSitting.IsNonPictrueMode;
            App.ManagerDB.SubmitChanges();
        }

        private void AutoLoadNextPage_Checked(object sender, RoutedEventArgs e)
        {
            App.appSitting.AutoLoadNextPage = true;
            App.ManagerDB.SubmitChanges();
        }

        private void AutoLoadNextPage_Unchecked(object sender, RoutedEventArgs e)
        {
            App.appSitting.AutoLoadNextPage = false;
            App.ManagerDB.SubmitChanges();
        }

        private void ReturnRrompt_Checked(object sender, RoutedEventArgs e)
        {
            App.appSitting.IsReturnRrompt = true;
            App.ManagerDB.SubmitChanges();
        }

        private void ReturnRrompt_Unchecked(object sender, RoutedEventArgs e)
        {
            App.appSitting.IsReturnRrompt = false;
            App.ManagerDB.SubmitChanges();
        }

        private void ReturnClear_Checked(object sender, RoutedEventArgs e)
        {
            App.appSitting.IsReturnClear = true;
            App.ManagerDB.SubmitChanges();
        }

        private void ReturnClear_Unchecked(object sender, RoutedEventArgs e)
        {
            App.appSitting.IsReturnClear = false;
            App.ManagerDB.SubmitChanges();
        }

        private void them_Loaded(object sender, RoutedEventArgs e)
        {
            them.SelectedIndex = App.appSitting.Theme;
            themloaded = true;
        }

        private void fontSize_Loaded(object sender, RoutedEventArgs e)
        {
            if (sender==null) return;
        }

        private void ListPicker_MouseLeave(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if (sender == null) return;
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                string filePath = "Xmls";
                String[] files = store.GetFileNames(filePath);
                for (int j = 0; j < files.Length; j++)
                {
                    String fPath = filePath + "\\" + files[j];
                    store.DeleteFile(fPath);
                }
            }
            ToastPrompt toastPrompt = new ToastPrompt() { Message = "缓存已清除" };
            toastPrompt.Show();
            return;
        }

        private void ListPicker_MouseLeave_user(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if (sender == null) return;
            string pageName = "/Page/userManager.xaml";
            NavigationService.Navigate(new Uri(pageName, UriKind.Relative));
        }
       
    }
}